/***********************************************************************************
 * 文件名： ENH-TV0028B015.c
 * 作者： 刘言
 * 版本： 1
 * 说明：
 *      ENH-TV0028B015 初始化函数
 * 修改记录：
 * 	2023/07/26: 初版。 刘言。
***********************************************************************************/
#include "st7789v.h"
#include "lcd_config.h"
#include "polsys.h"


// 函数名称固定，给 Lcd_Init 调用
// 初始化函数可能依据不同的屏幕其内容要做修改，建议参考屏幕厂商例程
void Lcd_ChipInit()
{
    _Lcd_PortInit();
    _Lcd_SetRstLevel(0);
    _Lcd_Delayms(10);
    _Lcd_SetRstLevel(1);
    // _Lcd_Delayms(120);
    _Lcd_Delayms(10);

    WriteOneByteCmd(_CMD_SOFT_RESET);
    _Lcd_Delayms(5);
    WriteOneByteCmd(_CMD_SLEEP_OUT);
    _Lcd_Delayms(5);

    WriteOneByteCmd(_CMD_MEM_ACCESS_CTRL);
    WriteOneByteData(0x60);// 0X00 竖屏，0X60横屏
    WriteOneByteCmd(_CMD_SET_IF_FMT);
    WriteOneByteData(0x05);
    WriteOneByteCmd(_CMD_DIS_INVERSION_ON); // 反向显示 

    WriteOneByteCmd(_CMD_PORCH_CTRL);
    WriteOneByteData(0X05);     //0C
    WriteOneByteData(0X05);     //0C
    WriteOneByteData(0X00);     
    WriteOneByteData(0X33);
    WriteOneByteData(0X33);
    WriteOneByteCmd(_CMD_GATE_CTRL1);
    WriteOneByteData(0X35);    //VGH=13V, VGL=-10.4V 

    WriteOneByteCmd(0XB8);   // 未知命令,包含在供应商提供的初始化代码
    WriteOneByteData(0X2F);
    WriteOneByteData(0X2B);
    WriteOneByteData(0X2F);
    WriteOneByteCmd(_CMD_SET_VCOM);
    WriteOneByteData(0X20); // 36
    WriteOneByteCmd(_CMD_LCM_CTRL);
    WriteOneByteData(0X2C);
    WriteOneByteCmd(_CMD_EN_VDV_VRH);
    WriteOneByteData(0X01);
    WriteOneByteCmd(_CMD_SET_VRH); 
    WriteOneByteData(0x0B); // 12 // GVDD=3.95V
    WriteOneByteCmd(_CMD_SET_VDV); 
    WriteOneByteData(0x20); 
    WriteOneByteCmd(_CMD_FR_CTRL2); 
    WriteOneByteData(0x11); // 0F
    WriteOneByteCmd(_CMD_POWER_CTRL1); 
    WriteOneByteData(0xa4); 
    WriteOneByteData(0xa1); 
    WriteOneByteCmd(_CMD_POWER_CTRL2);
    WriteOneByteData(0x03);
    WriteOneByteCmd(_CMD_EQ_TIME_CTRL);
    WriteOneByteData(0x0d);
    WriteOneByteData(0x12);
    WriteOneByteData(0x00);
    //----------------------------------------------------------------------------------------------------// 
    WriteOneByteCmd(_CMD_PV_GAM_CTRL);       //gamma setting 
    WriteOneByteData(0xd0); 
    WriteOneByteData(0x06); 
    WriteOneByteData(0x0B); 
    WriteOneByteData(0x0A); 
    WriteOneByteData(0x09); 
    WriteOneByteData(0x05); 
    WriteOneByteData(0x2E); 
    WriteOneByteData(0x43); 
    WriteOneByteData(0x44); 
    WriteOneByteData(0x09); 
    WriteOneByteData(0x16); 
    WriteOneByteData(0x15); 
    WriteOneByteData(0x23); 
    WriteOneByteData(0x27);
    
    WriteOneByteCmd(_CMD_NV_GAM_CTRL); 
    WriteOneByteData(0xd0); 
    WriteOneByteData(0x06); 
    WriteOneByteData(0x0B); 
    WriteOneByteData(0x09); 
    WriteOneByteData(0x08); 
    WriteOneByteData(0x06); 
    WriteOneByteData(0x2E); 
    WriteOneByteData(0x44); 
    WriteOneByteData(0x44); 
    WriteOneByteData(0x3A); 
    WriteOneByteData(0x15); 
    WriteOneByteData(0x15); 
    WriteOneByteData(0x23); 
    WriteOneByteData(0x26); 

    // WriteOneByteCmd(_CMD_DIS_ON);       //display on 
    // _Lcd_Delayms(120);
    WriteOneByteCmd(_CMD_WRITE_MEM);
}
